#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long a,b,c,d;
int main(){
	freopen("candy.in","r",stdin);
	freopen("candy.out","w",stdout);
	cin>>a>>b>>c;
	if(c/a-b/a>=1) cout<<a-1;
	else cout<<max(c%a,b%a);
}
